package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IRegionService;
import cn.wolfcode.luowowo.common.query.QueryObject;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/region")
@Controller
public class RegionController {
    @Reference
    private IRegionService regionService;
    @Reference
    private IDestinationService destinationService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo pageInfo = regionService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "region/list";
    }

    @RequestMapping("/listDests")
    @ResponseBody
    public Object listDests(){
        return destinationService.selectAllDests();
    }

    @RequestMapping("/listDestByRegionId")
    @ResponseBody
    public Object listDestByRegionId(Long rid){
        return destinationService.selectDestByRegionId(rid);
    }
}
